<template>
  <div class="login-wrap">
    <div class="login-wrap-img"></div>
    <div class="ms-login">
      <div class="ms-title">请销假后台管理</div>
      <el-form
        :model="param"
        :rules="rules"
        ref="login"
        label-width="0px"
        class="ms-content"
      >
        <el-form-item prop="username">
          <el-input
            v-model="param.username"
            placeholder="请输入你的登录账号"
            prefix-icon="el-icon-user"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            prefix-icon="el-icon-lock"
            type="password"
            placeholder="请输入您的密码"
            v-model="param.password"
            @keyup.enter.native="submitForm()"
            clearable
          >
          </el-input>
        </el-form-item>
        <div class="" style="padding-bottom: 15px">
          <el-checkbox v-model="isRemember">记住密码</el-checkbox>
        </div>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      param: {
        username: "",
        password: "",
      },
      isRemember: true,
      rules: {
        username: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    let musername = localStorage.getItem("musername");
    let mpassword = localStorage.getItem("mpassword");
    if (musername) {
      this.param.username = musername;
    }
    if (mpassword) {
      this.param.password = mpassword;
    }
  },
  methods: {
    yindaoRouter() {
      let eUrl = encodeURI("http://115.26.89.144");
      window.location.href =
        "http://authserver.tmu.edu.cn/authserver/oauth2.0/authorize?response_type=code&client_id=EoCOWF80&redirect_uri=" +
        eUrl +
        "&state=1";
    },
    submitForm() {
      let that = this;
      that.$router.push({
        path: "/",
      });
      return false;
      this.$refs.login.validate((valid) => {
        if (valid) {
          that.param.username = that.param.username.trim();
          that.param.password = that.param.password.trim();

          that
            .postAxios("/Web/Login", {
              UserName: that.param.username,
              PassWord: that.param.password, //syjones
            })
            .then((res) => {
              if (res.code == 0) {
                //是否保存密码
                if (that.isRemember) {
                  localStorage.setItem("musername", that.param.username);
                  localStorage.setItem("mpassword", that.param.password);
                }
                localStorage.setItem("dept", res.data.dept);
                localStorage.setItem("limit", res.data.limit);
                localStorage.setItem("username", res.data.username);
                localStorage.setItem("userId", res.data.id);
                let urlParam = this.getQueryVariable("redirect");
                if (urlParam) {
                  urlParam = unescape(urlParam);
                } else {
                  urlParam = "/";
                }
                console.log("urlParam", urlParam);
                that.$message({
                  message: "登录成功",
                  type: "success",
                  duration: 1000,
                  onClose: function () {
                    that.$router.push({
                      path: urlParam,
                    });
                  },
                });
              } else {
                that.$message({
                  message: res.msg,
                  type: "error",
                  duration: 1000,
                });
              }
            });
        } else {
          this.$message.error("请输入账号和密码");
          console.log("error submit!!");
          return false;
        }
      });
    },
    //获取url参数
    getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i in vars) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
      return false;
    },
  },
};
</script>

<style scoped lang="scss">
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  /*background-image: url(../../assets/img/login-bg.jpg);*/
  /*background-size: 100%;*/
}

.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: left;
  padding-left: 30px;
  font-size: 22px;
  color: #3395f9;
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 400px;
  height: auto;
  margin: -200px 0 0 -200px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 1);
  overflow: hidden;
  z-index: 10;
  padding: 20px 0;
  .yindao_wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
  }
}

.ms-content {
  padding: 30px 30px;
}

.login-btn {
  text-align: center;
}

.login-wrap .login-btn button {
  height: 45px;
  width: 100%;
  font-size: 14px;
}
.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #fff;
}
</style>